package com.lhb.controller;

import com.lhb.pojo.BaseResp;
import com.lhb.pojo.Comment;
import com.lhb.pojo.RotationImage;
import com.lhb.service.RotationService;
import com.lhb.utils.UploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.10.14 下午 23:55
 */
@RestController
@RequestMapping("rotation")
public class RotationController {

    @Autowired
    RotationService rotationService;

    @Autowired
    UploadUtils uploadUtils;

    @RequestMapping("/findAll")
    public BaseResp findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        return rotationService.findAll(page, limit);
    }

    //删除
    @RequestMapping(value = "del", method = RequestMethod.GET)
    public BaseResp delete(@RequestParam("id") Integer id) {
        rotationService.del(id);
        BaseResp baseResp = new BaseResp();
        baseResp.setCode(0);
        baseResp.setMsg("删除成功");
        return baseResp;
    }


    //图片上传
    @RequestMapping("/upload")
    public BaseResp upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        String upload = uploadUtils.upload(multipartFile);
        return new BaseResp(0, "上传成功！", null, upload);
    }

    @RequestMapping("/updateRotaion")
    public BaseResp update(@RequestBody RotationImage rotationImage) {
        return rotationService.updateRotation(rotationImage);
    }

    @RequestMapping("/insertRotation")
    public BaseResp AddComment(@RequestBody RotationImage rotationImage) {
        return rotationService.insertRotation(rotationImage);
    }

}
